<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>XXX后台管理</title>
    <script src="js/jquery-3.2.1.js"></script>
    <script src="layui/layui.js"></script>
    <script src="layui/lay/modules/layer.js"></script>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="layui/css/modules/layer/default/layer.css">
</head>
<body>
<div id="searchDiv" style="display: flex;justify-content: flex-start;margin-top: 8px;width: 30%">
    <label style="text-align: left;padding: 8px 0" class="layui-form-label">搜索</label>
    <input id="search_content" style="margin-right:10px;" type="text" name="title" required lay-verify="required"
           placeholder="请输入..." autocomplete="off" class="layui-input">
    <button class="layui-btn" data-type="reload">搜索</button>
</div>
<table id="demo" lay-filter="test"></table>
<script>
    layui.use('table', function () {
        var table = layui.table;

        //第一个实例
        table.render({
            elem: '#demo'
            , height: 500
            , url: 'getOrderSetActorList?publish_id=${publish_id}&order_feeScale_id=${order_feeScale_id}' //数据接口
            , cols: [[ //表头
                {field: 'indexTpl', title: '编号', width: 80, align: 'center', templet: '#indexID'}
                , {field: 'actor_name', align: 'center', title: '演员'}
                , {field: 'actor_sex', align: 'center', width: 80, title: '性别', templet: '#sex'}
                , {field: 'actor_tel', align: 'center', title: '手机号'}
                , {field: 'actor_profession', align: 'center', width: 150, title: '职务'}
                , {field: 'actor_diploma', align: 'center', width: 150, title: '学历'}
                , {field: 'title0', title: '近期出演', sort: false, align: 'center', width: 120, templet: '#zhuangtai'}
                , {field: 'title2', title: '已安排', align: 'center', width: 150, templet: '#anpai', event: 'anpai'}
            ]]
            , id: 'testReload'
            , page: true //开启分页
        });

        var $ = layui.$, active = {
            reload: function () {
                var demoReload = $('#search_content');
                //执行重载
                table.reload('testReload', {
                    url: 'searchOrderSetActorList?publish_id=${publish_id}'
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        title: demoReload.val()
                    }
                });
            }
        };
        $('#searchDiv .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        table.on('tool(test)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            //加入黑名单

            //删除
            if (layEvent === 'anpai') { //删除
                if (data.ke == 1) {
                    layer.confirm('确定将 ' + data.actor_name + ' 取消安排吗？', function (index) {
                        $.ajax({
                            type: "post",
                            url: "cancelActorToOrder",
                            data: {'order_feeScale_id': '${order_feeScale_id}', 'actor_id': data.actor_id},
                            success: function (res) {
                                // cancelActorToOrder
                                if (res.code == 0) {
                                    layer.close(index);
                                    layer.msg("安排成功！", {icon: 1});
                                    location.href = "orderInfoPage?order_id=${order_id}";
                                } else {
                                    layer.msg("发生错误！", {icon: 5})
                                }
                            }
                        });
                        layer.close(index);
                    });
                } else {
                    layer.confirm('确定将 ' + data.actor_name + ' 安排吗？', function (index) {
                        $.ajax({
                            type: "post",
                            url: "orderSetActorByFeeScale_id",
                            data: {"actor_id": data.actor_id, 'order_feeScale_id': '${order_feeScale_id}'},
                            success: function (res) {
                                if (res.code == 0) {
                                    layer.close(index);
                                    layer.msg("安排成功！", {icon: 1});
                                    location.href = "orderInfoPage?order_id=${order_id}";
                                } else {
                                    layer.msg("发生错误！", {icon: 5})
                                }
                            }
                        });
                        layer.close(index);
                    });
                }

            }
        });
    });
</script>

<script>
    //Demo
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function (data) {
        });
    });
</script>

<script type="text/html" id="lahei">
    <a href="javascript:;" class="layui-table-link">拉黑/恢复</a>
</script>
<script>
    //回车事件绑定
    $('#search_content').bind('keyup', function (event) {
        if (event.keyCode == "13") {
            //回车执行查询
            $('#searchDiv .layui-btn').click();
        }
    });
</script>
<script type="text/html" id="status">
    {{#  if(d.manager_status ==1){ }}
    正常
    {{#  } }}
    {{#  if(d.manager_status ==-1){ }}
    <span style="color: red"> 黑名单</span>
    {{#  } }}
</script>
<script type="text/html" id="sex">
    {{#  if(d.actor_sex ==1){ }}
    男
    {{#  } }}
    {{#  if(d.actor_sex ==0){ }}
    女
    {{#  } }}
</script>
<script type="text/html" id="indexID">
    {{ d.LAY_INDEX }}
</script>
<script type="text/html" id="edit">
    <a href="edit_actor_page?actor_id={{d.actor_id}}" class="layui-table-link">维护</a>
</script>
<script type="text/html" id="shanchu">
    <a href="javascript:;" class="layui-table-link">删除</a>
</script>
<script type="text/html" id="weihu">
    <a href="feeScaleListPage?pd_id={{d.pd_id}}" class="layui-table-link">查看</a>
</script>
<script type="text/html" id="zhuangtai">
    {{#  if(d.actor_status ==0){ }}
    <span style="color: green">正常</span>
    {{#  } }}
    {{#  if(d.actor_status !=0){ }}
    <span style="color: red">外勤中</span>
    {{#  } }}
</script>
<script type="text/html" id="anpai">
    {{#  if(d.ke ==0){ }}
    <span style="color: #2D93CA">安排</span>
    {{#  } }}
    {{#  if(d.ke ==1){ }}
    <span style="color: red">取消安排</span>
    {{#  } }}
</script>

</body>
</html>